using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ProjectIndieFarm
{
    [RequireComponent(typeof(BoxCollider2D))]
    public class AutoHideDetect : MonoBehaviour
    {
        public Collider2D collider2d;
        public SpriteRenderer[] sprites;

        private void Start()
        {
            collider2d.OnTriggerEnter2DEvent((coll) =>
            {
                if (coll.CompareTag("Player"))
                {
                    foreach (var sprite in sprites)
                    {
                        ActionKit.Lerp(sprite.color.a, 0.5f, 0.3f, progress =>
                        {
                            sprite.Alpha(progress);
                        }).Start(this);
                    }
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);

            collider2d.OnTriggerExit2DEvent((coll) =>
            {
                if (coll.CompareTag("Player"))
                {
                    foreach (var sprite in sprites)
                    {
                        ActionKit.Lerp(sprite.color.a, 1.0f, 0.3f, progress =>
                        {
                            sprite.Alpha(progress);
                        }).Start(this);
                    }
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
        }
    }
}